"""
    @author yu_chen
    @date  
    @todo 
"""
import urllib
import os


class FileUtil:
    def __init__(self):
        return

    @staticmethod
    def download_mp3(download_url, file_name):
        """
        下载mp3歌曲
        :param download_url: 下载地址
        :param file_name: 下载后存储的文件名
        :return:
        """
        try:
            # os.mkdir(os.path.split(file_name)[0])
            os.makedirs(os.path.split(file_name)[0], exist_ok=True)
            print('正在下载歌曲：%s 歌曲下载地址：%s' % (file_name, download_url))
            urllib.request.urlretrieve(download_url, file_name)
            print('下载歌曲完毕：' + file_name)
        except Exception as e:
            print('下载歌曲失败：' + e.message)


if __name__ == '__main__':
    songs_name = 'a'
    FileUtil.download_mp3("http://music.163.com/song/media/outer/url?id=1396162013.mp3",
                          '../mp3/' + songs_name + '.mp3')
